﻿
namespace Heimdallr.Net
{
    /// <summary>
    /// Represents the module of <see cref="HttpElement"/> which is for handling outgoing responses and publishing notifications.
    /// </summary>
    public interface IHttpResponseModule
    {
        #region Property

        /// <summary>
        /// Gets the HTTP method.
        /// </summary>
        string Method { get; }

        /// <summary>
        /// Gets the relative path.
        /// </summary>
        string RelativePath { get; }

        /// <summary>
        /// Gets the credential type.
        /// </summary>
        HttpModuleCredentialType CredentialType { get; }

        #endregion

        #region Method

        /// <summary>
        /// Indicates if user name and password of incoming request is valid or not.
        /// </summary>
        /// <param name="username">User name of incoming request.</param>
        /// <param name="password">Password of incoming request.</param>
        /// <returns>If valid, the return value is true. Otherwise false.</returns>
        bool Validate(string username, string password);

        /// <summary>
        /// Registers an alive response previously which has prepared for notifying.
        /// </summary>
        /// <param name="response">An alive response created and passed by <see cref="HttpElement"/>.</param>
        /// <returns>If success, return true. Otherwise return false.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="response"/> is null.</exception>
        bool RegisterContext(HttpResponseContext response);

        /// <summary>
        /// Publishes a notification to all registered <see cref="HttpResponseContext"/> instances.
        /// </summary>
        /// <param name="notification">A notification which is going to be published.</param>
        /// <exception cref="ArgumentNullException"><paramref name="notification"/> is null.</exception>
        void Publish(Notification notification);


        #endregion
    }
}